package com.lihh.rocket5.normal;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.io.UnsupportedEncodingException;

public class SyncProducer001 {
  public static void main(String[] args) throws UnsupportedEncodingException, MQBrokerException, RemotingException, InterruptedException, MQClientException {
    DefaultMQProducer producer = new DefaultMQProducer("sync-producer-666");
    producer.setNamesrvAddr("127.0.0.1:9876");
    
    // 同步发送消息
    for (int i = 0; i < 10; i++) {
      Message message = new Message("topic111", "tagA", ("hello, a" + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
      SendResult send = producer.send(message);
      System.out.println(send);
    }
    
    producer.start();
    System.out.println("producer 生产者消费发送完成 ...");
  }
}
